<!DOCTYPE html>
<html lang="chinese">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>widget</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.7.14/dist/vue.js"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css" rel="stylesheet">
    <!-- 引入样式 -->
    <link href="https://unpkg.com/element-ui@latest/lib/theme-chalk/index.css" rel="stylesheet">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui@latest/lib/index.js"></script>
    <script src="../app/lib/ZohoCrmHelper.js" type="text/javascript"></script>
    <script src="../app/lib/ZSDK.js" type="text/javascript"></script>
    <script src="../app/lib/jquery-1.10.2.js" type="text/javascript"></script>
    <script src="../app/lib/ZohoEmbededAppSDK.min.js" type="text/javascript"></script>
    <script src="../app/lib/axios.min.js" type="text/javascript"></script>
    <style>
        .el-form-item__content {
            margin-left: 0 !important;
        }

        .custom-checkbox {
            display: flex; /* 使用 Flexbox 布局 */
            align-items: flex-start; /* 让复选框和文字在顶部对齐 */
            width: 100%; /* 可根据需要调整宽度 */
            margin-bottom: 10px;
        }

        .custom-checkbox .el-checkbox__label {
            white-space: normal;
            word-wrap: break-word;
        }

        .el-radio input[aria-hidden="true"] {
            display: none !important;
        }

        .el-radio:focus:not(.is-focus):not(:active):not(.is-disabled) .el-radio__inner {
            box-shadow: none !important;
        }

        /* 让容器居中并设置宽度为屏幕的 60% */
        .container {
            width: 60%;
            margin: 0 auto;
            padding-top: 5px; /* 可以根据需要调整顶部间距 */
        }

        .layout_logo__HgfU9 {
            width: auto;
            height: 20px;
            vertical-align: middle;

        }

        /* 新增样式，使用 Flexbox 布局 */
        header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 50px;
        }

        .form-title {
            text-align: center;
            font-size: 30px;
            font-weight: 600;
            margin-bottom: 24px;
        }

        /* 新增样式使 label 左对齐 */
        .el-form-item__label {
            text-align: left;
        }

        .upload-demo {
            text-align: center;
        }
    </style>
</head>
<body>
<div id="app" class="container">

    <header>
        <a aria-label="index" href="https://www.chainup.com/" class="logo-link">
            <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 121 20" class="layout_logo__HgfU9">
                <g fill-rule="evenodd" clip-path="url(#header-logo_svg__a)" clip-rule="evenodd">
                    <path fill="#011127"
                          d="M43.848 17.314c-3.425 0-7.11-2.242-7.11-7.165 0-4.922 3.685-7.164 7.11-7.164 1.189 0 2.426.39 3.894 1.23.089.051.34.22.34.22l-1.477 2.07s-1.463-.943-2.737-.943c-1.365 0-2.51.494-3.31 1.428-.712.832-1.105 1.954-1.105 3.16 0 2.208 1.382 4.586 4.415 4.586 1.002 0 1.774-.291 2.396-.736.13-.092.34-.228.34-.228l1.483 2.07s-.233.174-.318.235c-1.148.828-2.29 1.236-3.92 1.236M50.477 17.014h2.688v-3.88h-2.688zM59.229 3.283V8.93h-6.154V3.283h-2.598v8.086h8.751999999999999v5.646h2.598V3.283zM77.06 17.015l-6.72-14.03-6.721 14.03h2.776l3.944-8.253 1.782 3.888h-2.174l-1.214 2.468h4.61l.94 1.897zM78.851 17.015h2.688V3.283h-2.688z"></path>
                    <path fill="#095BE8"
                          d="M115.98 3.284h-4.572v2.4530000000000003h4.572c1.397 0 2.034 1.055 2.034 2.036 0 .534-.18 1.03-.507 1.397-.368.412-.896.63-1.527.63h-2.611v-.007h-1.961v7.221h2.588v-4.768000000000001h1.96v.005c.251-.001.443-.006.592-.018 2.83-.244 4.119-2.48 4.119-4.455 0-2.165-1.467-4.494-4.687-4.494M108.627 3.283h-2.174v.376c0 .007-.004.012-.004.019v7.611c0 2.057-1.533 2.993-2.957 2.993s-2.958-.936-2.958-2.993V3.678q-.001-.01-.003-.02v-.375h-2.565v8.006c0 2.845 1.898 5.726 5.526 5.726 2.661 0 5.525-1.792 5.525-5.726V3.283z"></path>
                    <path fill="#011127"
                          d="M92.963 3.284v7.682l-8.735-7.682v3.745l11.35 9.986V3.284zM83.93 17.015h2.687v-5.188L83.93 9.552zM8.446 4.18 4.48 1.971 7.982 0l3.965 2.206zM23.596 11.531 8.864 20 0 14.852V4.556l2.727-1.57 3.58 2.054L3.56 6.625v6.16l5.304 3.08 11.172-6.401z"></path>
                    <path fill="#095BE8"
                          d="m23.836 15.82 3.643 2.1L23.95 20l-3.64-2.097zM8.96 8.234 23.1 0l8.859 5.148v10.296l-2.726 1.57-3.579-2.054 2.747-1.585v-6.16L23.1 4.136 12.518 10.3z"></path>
                </g>
                <defs>
                    <clipPath id="header-logo_svg__a">
                        <path fill="#fff" d="M0 0h120.667v20H0z"></path>
                    </clipPath>
                </defs>
            </svg>
        </a>

        <el-select v-model="currentLanguage" placeholder="请选择">
            <el-option label="繁体中文" value="chinese" @click="switchLanguage('chinese')"></el-option>
            <el-option label="English" value="english" @click="switchLanguage('english')"></el-option>
        </el-select>
    </header>

    <!--        表头-->
    <h2 class="form-title">KYC 入職表格（公司）</h2>

    <el-form :model="formData" :rules="dynamicRules" ref="myForm" label-width="150px">
        <el-form-item label="注册公司名稱" prop="Account_Name">
            <el-input v-model="formData.Account_Name" disabled></el-input>
        </el-form-item>

        <el-form-item label="公司註冊地" prop="companyRegistrationPlace">
            <el-select v-model="formData.companyRegistrationPlace" placeholder="请选择" filterable remote>
                <el-option
                        v-for="item in countries"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                </el-option>
            </el-select>
        </el-form-item>

        <el-form-item label="註冊地址" prop="Zc_Street">
            <el-input v-model="formData.Zc_Street"></el-input>
        </el-form-item>
        <el-form-item label="聯絡電話" prop="Phone">
            <el-input v-model="formData.Phone"></el-input>
        </el-form-item>
        <el-form-item label="電子郵件" prop="Email">
            <el-input v-model="formData.Email"></el-input>
        </el-form-item>

        <el-form-item label="有多少最終受益人？" prop="beneficialOwners">
            <el-select v-model="formData.beneficialOwners" @change="changeUserForm()" filterable remote>
                <el-option label="1" value="1"></el-option>
                <el-option label="2" value="2"></el-option>
                <el-option label="3" value="3"></el-option>
                <el-option label="4" value="4"></el-option>
            </el-select>
        </el-form-item>

        <p>最終受益人 (1)</p>
        <el-form-item label="法定全名/全名" prop="fullLegalName_1">
            <el-input v-model="formData.fullLegalName_1"></el-input>
        </el-form-item>
        <el-form-item label="公司註冊地/國籍" prop="nationality_1">
            <el-select v-model="formData.nationality_1" placeholder="请选择" filterable remote>
                <el-option
                        v-for="item in countries"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                </el-option>
            </el-select>

        </el-form-item>
        <el-form-item label="註冊地址/居住地址" prop="registerAddress_1">
            <el-input v-model="formData.registerAddress_1"></el-input>
        </el-form-item>
        <el-form-item label="股權權益（%）" prop="equity_1">
            <el-input v-model="formData.equity_1"></el-input>
        </el-form-item>
        <div v-if="formData.finalUserShow_2">
            <p>最終受益人 (2)</p>
            <el-form-item label="法定全名/全名" prop="fullLegalName_2">
                <el-input v-model="formData.fullLegalName_2"></el-input>
            </el-form-item>
            <el-form-item label="公司註冊地/國籍" prop="nationality_2">
                <el-select v-model="formData.nationality_2" placeholder="请选择" filterable remote>
                    <el-option
                            v-for="item in countries"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="註冊地址/居住地址" prop="registerAddress_2">
                <el-input v-model="formData.registerAddress_2"></el-input>
            </el-form-item>
            <el-form-item label="股權權益（%）" prop="equity_2">
                <el-input v-model="formData.equity_2"></el-input>
            </el-form-item>
        </div>

        <div v-if="formData.finalUserShow_3">
            <p>最終受益人 (3)</p>
            <el-form-item label="法定全名/全名" prop="fullLegalName_3">
                <el-input v-model="formData.fullLegalName_3"></el-input>
            </el-form-item>
            <el-form-item label="公司註冊地/國籍" prop="nationality_3">
                <el-select v-model="formData.nationality_3" placeholder="请选择" filterable remote>
                    <el-option
                            v-for="item in countries"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="註冊地址/居住地址" prop="registerAddress_3">
                <el-input v-model="formData.registerAddress_3"></el-input>
            </el-form-item>
            <el-form-item label="股權權益（%）" prop="equity_3">
                <el-input v-model="formData.equity_3"></el-input>
            </el-form-item>
        </div>

        <div v-if="formData.finalUserShow_4">
            <p>最終受益人 (4)</p>
            <el-form-item label="法定全名/全名" prop="fullLegalName_4">
                <el-input v-model="formData.fullLegalName_4"></el-input>
            </el-form-item>
            <el-form-item label="公司註冊地/國籍" prop="nationality_4">
                <el-select v-model="formData.nationality_4" placeholder="请选择" filterable remote>
                    <el-option
                            v-for="item in countries"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="註冊地址/居住地址" prop="registerAddress_4">
                <el-input v-model="formData.registerAddress_4"></el-input>
            </el-form-item>
            <el-form-item label="股權權益（%）" prop="equity_4">
                <el-input v-model="formData.equity_4"></el-input>
            </el-form-item>
        </div>

        <el-form-item label="授權簽字人（每位簽字人以 [,] 逗號分隔）" prop="Qianziren" label-width="300px">
            <el-input v-model="formData.Qianziren"></el-input>
        </el-form-item>

        <el-form-item label="主體主要業務的說明" prop="Yewu_Shuoming">
            <el-input v-model="formData.Yewu_Shuoming"></el-input>
        </el-form-item>
        <el-form-item label="資金來源（例如資產負債表、銀行帳戶對帳單）" prop="Zijin_Laiyuan" label-width="450px">
            <el-input v-model="formData.Zijin_Laiyuan"></el-input>
        </el-form-item>


        <el-form-item label="申請人（授權簽字人、受益所有人）是政治公眾人物 (PEP) 還是 PEP 的家人或親密夥伴？" prop="Shenqingren" label-width="650px">
            <el-radio-group v-model="formData.Shenqingren">
                <el-radio :label="1">是</el-radio>
                <el-radio :label="0">否</el-radio>
            </el-radio-group>
        </el-form-item>
        <el-form-item label="申請人是否受任何司法管轄區監管？" prop="IsJianguan" label-width="650px">
            <el-radio-group v-model="formData.IsJianguan">
                <el-radio :label="1">是</el-radio>
                <el-radio :label="0">否</el-radio>
            </el-radio-group>
        </el-form-item>
        <el-form-item label="申請人或其任何受益所有人是否受到任何主管機關的製裁？" prop="IsZhicai" label-width="650px">
            <el-radio-group v-model="formData.IsZhicai">
                <el-radio :label="1">是</el-radio>
                <el-radio :label="0">否</el-radio>
            </el-radio-group>
        </el-form-item>

        <p>需上傳的文件</p>
        <div v-if="formData.file_1_show">
            <p>1. 註冊/成立文件</p>
            <p>請提供以下任一文件以顯示股東和董事資訊</p>
            <ul>
                <li>公司登記處/公司概況搜尋報告</li>
                <li>註冊/成立證書和股東名冊</li>
                <li>在任證明</li>
            </ul>

            <el-form-item prop="file_1">
                <el-upload
                        drag
                        action="https://jsonplaceholder.typicode.com/posts/"
                        class="upload-demo"
                        :file-list="formData.file_1_List"
                        :auto-upload="false"
                        multiple
                        :limit="5"
                        :on-exceed="handleExceed"
                        accept=".zip,.pdf,.jpeg,.jpg,.png,.tiff,.pptx,.docx,.xlsx"
                        :on-change="(file, fileList) => handleChange(file, fileList, 1)"
                        :before-upload="beforeAvatarUpload"
                        :on-remove="handleRemove"
                >
                    <i class="el-icon-upload"></i>
                    <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
                    <div class="el-upload__tip" slot="tip">支援格式：Zip、pdf、jpeg、jpg、png、tiff、pptx、Word、Excel。最大尺寸：20MB
                    </div>
                </el-upload>
            </el-form-item>
        </div>

        <div v-if="formData.file_2_show">
            <p>2. 對於所有受益所有人（以及授權簽字人，如果已指定），請為每個人提供以下其中一項：</p>
            <ul>
                <li>身分證（僅限新加坡人）或護照（非新加坡人）</li>
                <li>如果身分證或護照上沒有地址，請提供地址證明。</li>
            </ul>
            <p>
                可接受的地址證明形式包括但不限於：最近3個月（從提交KYC表格或合約日期算起）的公用事業帳單/電話帳單/銀行對帳單/個人所在國家的任何外國當局或相關機構發送的信函正在居住。如果文件是外語（不是英文），則必須翻譯成英文。</p>
            <el-form-item prop="file_2">
                <el-upload
                        drag
                        action="https://jsonplaceholder.typicode.com/posts/"
                        class="upload-demo"
                        :file-list="formData.file_2_List"
                        :auto-upload="false"
                        multiple
                        :limit="5"
                        :on-exceed="handleExceed"
                        accept=".zip,.pdf,.jpeg,.jpg,.png,.tiff,.pptx,.docx,.xlsx"
                        :on-change="(file, fileList) => handleChange(file, fileList, 2)"
                        :before-upload="beforeAvatarUpload"
                        :on-remove="handleRemove"
                >
                    <i class="el-icon-upload"></i>
                    <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
                    <div class="el-upload__tip" slot="tip">支援格式：Zip、pdf、jpeg、jpg、png、tiff、pptx、Word、Excel。最大尺寸：20MB
                    </div>
                </el-upload>
            </el-form-item>
        </div>

        <div v-if="formData.file_3_show">
            <p>3. 若指定了授權簽字人，請提供下列其中一項：</p>
            <ul>
                <li>指明授權簽署人名單的董事會決議</li>
                <li>註明授權簽字人名單的董事會會議紀錄</li>
            </ul>
            <el-form-item prop="file_3">
                <el-upload
                        drag
                        action="https://jsonplaceholder.typicode.com/posts/"
                        class="upload-demo"
                        :file-list="formData.file_3_List"
                        :auto-upload="false"
                        multiple
                        :limit="5"
                        :on-exceed="handleExceed"
                        accept=".zip,.pdf,.jpeg,.jpg,.png,.tiff,.pptx,.docx,.xlsx"
                        :on-change="(file, fileList) => handleChange(file, fileList, 3)"
                        :before-upload="beforeAvatarUpload"
                        :on-remove="handleRemove"
                >
                    <i class="el-icon-upload"></i>
                    <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
                    <div class="el-upload__tip" slot="tip">支援格式：Zip、pdf、jpeg、jpg、png、tiff、pptx、Word、Excel。最大尺寸：20MB
                    </div>
                </el-upload>
            </el-form-item>
        </div>

        <div v-if="formData.file_4_show">
            <p>4. 董事請提供身分證（新加坡人）或護照（非新加坡人）。</p>
            <el-form-item prop="file_4">
                <el-upload
                        drag
                        action="https://jsonplaceholder.typicode.com/posts/"
                        class="upload-demo"
                        :file-list="formData.file_4_List"
                        :auto-upload="false"
                        multiple
                        :limit="5"
                        :on-exceed="handleExceed"
                        accept=".zip,.pdf,.jpeg,.jpg,.png,.tiff,.pptx,.docx,.xlsx"
                        :on-change="(file, fileList) => handleChange(file, fileList, 4)"
                        :before-upload="beforeAvatarUpload"
                        :on-remove="handleRemove"
                >
                    <i class="el-icon-upload"></i>
                    <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
                    <div class="el-upload__tip" slot="tip">支援格式：Zip、pdf、jpeg、jpg、png、tiff、pptx、Word、Excel。最大尺寸：20MB
                    </div>
                </el-upload>
            </el-form-item>
        </div>


        <p>宣言</p>
        <el-form-item prop="declaration_check_1">
            <el-checkbox v-model="formData.declaration_check_1" class="custom-checkbox">
                我/我們特此確認，上述提供給您的資訊在我/我們所知範圍內真實且準確。我/我們承認，如果發現所提供的資訊為虛假或誤導，您有權隨時終止業務關係。我/我們特此同意提供可能需要的任何額外資訊/文件。
            </el-checkbox>
        </el-form-item>

        <el-form-item prop="declaration_check_2">
            <el-checkbox v-model="formData.declaration_check_2" class="custom-checkbox">
                我/我們承認並同意 ChainUp Group 的隱私權政策 https://www.chainup.com/privacyPolicy ，並同意 ChainUp Group
                出於隱私權政策中規定的目的收集、使用和揭露我的個人資料。
            </el-checkbox>
        </el-form-item>

        <el-form-item>
            <el-button type="primary" @click="submitForm('myForm')">
                {{ isSubmitting ? '提交中...' : '提交' }}
            </el-button>
            <el-button @click="resetForm('myForm')">重置</el-button>
        </el-form-item>
    </el-form>

</div>

<script>
    const app = new Vue({
        el: '#app',
        data() {
            return {
                isSubmitting: false, // 新增：提交状态
                crmId: "",
                currentLanguage: 'chinese', // 当前系统语言
                MAX_FILE_SIZE: 20 * 1024 * 1024, // 文件大小 20MB
                // 允许的文件格式
                allowedExtensions: [
                    'zip', 'pdf', 'jpeg', 'jpg', 'png', 'tiff', 'pptx', 'docx', 'xlsx'
                ],
                // 国家
                countries: [
                    {value: '阿富汗', name: 'afghanistan'},
                    {value: '阿尔巴尼亚', name: 'albania'},
                    {value: '阿尔及利亚', name: 'algeria'},
                    {value: '安哥拉', name: 'angola'},
                    {value: '阿根廷', name: 'argentina'},
                    {value: '亚美尼亚', name: 'armenia'},
                    {value: '澳大利亚', name: 'australia'},
                    {value: '奥地利', name: 'austria'},
                    {value: '阿塞拜疆', name: 'azerbaijan'},
                    {value: '巴林', name: 'bahrain'},
                    {value: '孟加拉国', name: 'bangladesh'},
                    {value: '白俄罗斯', name: 'belarus'},
                    {value: '比利时', name: 'belgium'},
                    {value: '伯利兹', name: 'belize'},
                    {value: '贝宁', name: 'benin'},
                    {value: '不丹', name: 'bhutan'},
                    {value: '玻利维亚', name: 'bolivia'},
                    {value: '波斯尼亚和黑塞哥维那', name: 'bosnia'},
                    {value: '博茨瓦纳', name: 'botswana'},
                    {value: '巴西', name: 'brazil'},
                    {value: '英属维京群岛', name: 'british-virgin-islands'},
                    {value: '文莱', name: 'brunei'},
                    {value: '保加利亚', name: 'bulgaria'},
                    {value: '布基纳法索', name: 'burkina-faso'},
                    {value: '布隆迪', name: 'burundi'},
                    {value: '柬埔寨', name: 'cambodia'},
                    {value: '喀麦隆', name: 'cameroon'},
                    {value: '加拿大', name: 'canada'},
                    {value: '佛得角', name: 'cape-verde'},
                    {value: '开曼群岛', name: 'cayman-islands'},
                    {value: '中非共和国', name: 'central-african-republic'},
                    {value: '乍得', name: 'chad'},
                    {value: '智利', name: 'chile'},
                    {value: '中国', name: 'china'},
                    {value: '哥伦比亚', name: 'colombia'},
                    {value: '科摩罗', name: 'comoros'},
                    {value: '刚果(布)', name: 'congo-brazzaville'},
                    {value: '刚果(金)', name: 'congo-kinshasa'},
                    {value: '哥斯达黎加', name: 'costarica'},
                    {value: '克罗地亚', name: 'croatia'},
                    {value: '塞浦路斯', name: 'cyprus'},
                    {value: '捷克共和国', name: 'czech-republic'},
                    {value: '丹麦', name: 'denmark'},
                    {value: '吉布提', name: 'djibouti'},
                    {value: '多米尼加共和国', name: 'dominican-republic'},
                    {value: '厄瓜多尔', name: 'ecuador'},
                    {value: '埃及', name: 'egypt'},
                    {value: '萨尔瓦多', name: 'el-salvador'},
                    {value: '赤道几内亚', name: 'equatorial-guinea'},
                    {value: '厄立特里亚', name: 'eritrea'},
                    {value: '爱沙尼亚', name: 'estonia'},
                    {value: '埃塞俄比亚', name: 'ethiopia'},
                    {value: '斐济', name: 'fiji'},
                    {value: '芬兰', name: 'finland'},
                    {value: '法国', name: 'france'},
                    {value: '加蓬', name: 'gabon'},
                    {value: '冈比亚', name: 'gambia'},
                    {value: '格鲁吉亚', name: 'georgia'},
                    {value: '德国', name: 'germany'},
                    {value: '加纳', name: 'ghana'},
                    {value: '希腊', name: 'greece'},
                    {value: '格陵兰', name: 'greenland'},
                    {value: '危地马拉', name: 'guatemala'},
                    {value: '几内亚', name: 'guinea'},
                    {value: '圭亚那', name: 'guyana'},
                    {value: '海地', name: 'haiti'},
                    {value: '洪都拉斯', name: 'honduras'},
                    {value: '中国香港特别行政区', name: 'hong-kong'},
                    {value: '匈牙利', name: 'hungary'},
                    {value: '冰岛', name: 'iceland'},
                    {value: '印度', name: 'india'},
                    {value: '印度尼西亚', name: 'indonesia'},
                    {value: '伊朗', name: 'iran'},
                    {value: '伊拉克', name: 'iraq'},
                    {value: '爱尔兰', name: 'ireland'},
                    {value: '马恩岛', name: 'isle-of-man'},
                    {value: '以色列', name: 'israel'},
                    {value: '意大利', name: 'italy'},
                    {value: '科特迪瓦', name: 'ivory-coast'},
                    {value: '牙买加', name: 'jamaica'},
                    {value: '日本', name: 'japan'},
                    {value: '约旦', name: 'jordan'},
                    {value: '哈萨克斯坦', name: 'kazakhstan'},
                    {value: '肯尼亚', name: 'kenya'},
                    {value: '韩国', name: 'south-korea'},
                    {value: '科威特', name: 'kuwait'},
                    {value: '吉尔吉斯斯坦', name: 'kyrgyzstan'},
                    {value: '老挝', name: 'laos'},
                    {value: '拉脱维亚', name: 'latvia'},
                    {value: '黎巴嫩', name: 'lebanon'},
                    {value: '莱索托', name: 'lesotho'},
                    {value: '利比里亚', name: 'liberia'},
                    {value: '利比亚', name: 'libya'},
                    {value: '立陶宛', name: 'lithuania'},
                    {value: '卢森堡', name: 'luxembourg'},
                    {value: '中国澳门特别行政区', name: 'macau'},
                    {value: '马其顿', name: 'macedonia'},
                    {value: '马达加斯加', name: 'madagascar'},
                    {value: '马拉维', name: 'malawi'},
                    {value: '马来西亚', name: 'malaysia'},
                    {value: '马尔代夫', name: 'maldives'},
                    {value: '马里', name: 'mali'},
                    {value: '马耳他', name: 'malta'},
                    {value: '毛利塔尼亚', name: 'mauritania'},
                    {value: '毛里求斯', name: 'mauritius'},
                    {value: '墨西哥', name: 'mexico'},
                    {value: '摩尔多瓦', name: 'moldova'},
                    {value: '摩纳哥', name: 'monaco'},
                    {value: '蒙古', name: 'mongolia'},
                    {value: '黑山共和国', name: 'montenegro'},
                    {value: '摩洛哥', name: 'morocco'},
                    {value: '莫桑比克', name: 'mozambique'},
                    {value: '缅甸', name: 'myanmar'},
                    {value: '纳米比亚', name: 'namibia'},
                    {value: '尼泊尔', name: 'nepal'},
                    {value: '荷兰', name: 'netherlands'},
                    {value: '新西兰', name: 'new-zealand'},
                    {value: '尼加拉瓜', name: 'nicaragua'},
                    {value: '尼日尔', name: 'niger'},
                    {value: '尼日利亚', name: 'nigeria'},
                    {value: '朝鲜', name: 'north-korea'},
                    {value: '挪威', name: 'norway'},
                    {value: '阿曼', name: 'oman'},
                    {value: '巴基斯坦', name: 'pakistan'},
                    {value: '巴拿马', name: 'panama'},
                    {value: '巴拉圭', name: 'paraguay'},
                    {value: '秘鲁', name: 'peru'},
                    {value: '菲律宾', name: 'philippines'},
                    {value: '波兰', name: 'poland'},
                    {value: '葡萄牙', name: 'portugal'},
                    {value: '波多黎各', name: 'puerto-rico'},
                    {value: '卡塔尔', name: 'qatar'},
                    {value: '留尼旺', name: 'reunion'},
                    {value: '罗马尼亚', name: 'romania'},
                    {value: '俄罗斯', name: 'russia'},
                    {value: '卢旺达', name: 'rwanda'},
                    {value: '圣马力诺', name: 'san-marino'},
                    {value: '沙特阿拉伯', name: 'saudi-arabia'},
                    {value: '塞内加尔', name: 'senegal'},
                    {value: '塞尔维亚', name: 'serbia'},
                    {value: '塞拉利昂', name: 'sierra-leone'},
                    {value: '新加坡', name: 'singapore'},
                    {value: '斯洛伐克', name: 'slovakia'},
                    {value: '斯洛文尼亚', name: 'slovenia'},
                    {value: '索马里', name: 'somalia'},
                    {value: '南非', name: 'south-africa'},
                    {value: '西班牙', name: 'spain'},
                    {value: '斯里兰卡', name: 'sri-lanka'},
                    {value: '苏丹', name: 'sudan'},
                    {value: '苏里南', name: 'suriname'},
                    {value: '斯威士兰', name: 'swaziland'},
                    {value: '瑞典', name: 'sweden'},
                    {value: '瑞士', name: 'switzerland'},
                    {value: '叙利亚', name: 'syria'},
                    {value: '中国台湾', name: 'taiwan'},
                    {value: '塔吉克斯坦', name: 'tajikistan'},
                    {value: '坦桑尼亚', name: 'tanzania'},
                    {value: '泰国', name: 'thailand'},
                    {value: '多哥', name: 'togo'},
                    {value: '汤加', name: 'tonga'},
                    {value: '特立尼达和多巴哥', name: 'trinidad-and-tobago'},
                    {value: '突尼斯', name: 'tunisia'},
                    {value: '土耳其', name: 'turkey'},
                    {value: '土库曼斯坦', name: 'turkmenistan'},
                    {value: '美属维尔京群岛', name: 'us-virgin-islands'},
                    {value: '乌干达', name: 'uganda'},
                    {value: '乌克兰', name: 'ukraine'},
                    {value: '阿拉伯联合酋长国', name: 'united-arab-emirates'},
                    {value: '英国', name: 'united-kingdom'},
                    {value: '美国', name: 'united-states'},
                    {value: '乌拉圭', name: 'uruguay'},
                    {value: '乌兹别克斯坦', name: 'uzbekistan'},
                    {value: '梵蒂冈城', name: 'vatican'},
                    {value: '委内瑞拉', name: 'venezuela'},
                    {value: '越南', name: 'vietnam'},
                    {value: '也门', name: 'yemen'},
                    {value: '南斯拉夫', name: 'yugoslavia'},
                    {value: '扎伊尔', name: 'zair'},
                    {value: '赞比亚', name: 'zambia'},
                    {value: '津巴布韦', name: 'zimbabwe'}
                ],
                // 表单数据
                formData: {
                    id: '',
                    Account_Name: '123123123',
                    companyRegistrationPlace: '',
                    Zc_Street: '',
                    Qianziren: '',
                    Yewu_Shuoming: '',
                    Zijin_Laiyuan: '',
                    Shenqingren: '',
                    IsJianguan: '',
                    IsZhicai: '',
                    beneficialOwners: '', // 多少受益人
                    country: '',
                    birthDate: '',
                    fileNumber_1: '',
                    fileNumber_2: '',
                    fileNumber_3: '',
                    agreement: '',
                    Phone: '',
                    Email: '',
                    fullLegalName_1: '',
                    nationality_1: '',
                    registerAddress_1: '',
                    equity_1: '',
                    fullLegalName_2: '',
                    nationality_2: '',
                    registerAddress_2: '',
                    equity_2: '',
                    fullLegalName_3: '',
                    nationality_3: '',
                    registerAddress_3: '',
                    equity_3: '',
                    fullLegalName_4: '',
                    nationality_4: '',
                    registerAddress_4: '',
                    equity_4: '',
                    finalUserShow_2: false,
                    finalUserShow_3: false,
                    finalUserShow_4: false,
                    fileTitle: '',
                    fileTitle_1: '',
                    fileTitle_1_content: '',
                    fileTitle_1_detail_1: '',
                    fileTitle_1_detail_2: '',
                    fileTitle_1_detail_3: '',
                    fileTitle_2: '',
                    fileTitle_2_content: '',
                    fileTitle_2_detail_1: '',
                    fileTitle_2_detail_2: '',
                    fileTitle_3: '',
                    fileTitle_3_detail_1: '',
                    fileTitle_3_detail_2: '',
                    fileTitle_4: '',
                    check_1: '',
                    check_2: '',
                    file_1: null,
                    file_1_List: [], // 上传的文件列表
                    file_2: null,
                    file_2_List: [], // 上传的文件列表
                    file_3: null,
                    file_3_List: [], // 上传的文件列表
                    file_4: null,
                    file_4_List: [], // 上传的文件列表
                    file_1_show: true, // 文件1是否展示
                    file_2_show: true, // 文件2是否展示
                    file_3_show: true, // 文件3是否展示
                    file_4_show: true, // 文件4是否展示
                    KYC_Info: [], // crm 文件 子表单
                },
            };
        },
        mounted() {
            this.initData();
            ZOHO.embeddedApp.init();
        },
        computed: {
            // 动态生成验证规则
            dynamicRules() {
                return {
                    // Account_Name: [
                    //     {required: true, message: '请输入注册公司名稱', trigger: 'blur'},
                    //     {min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur'}
                    // ],
                    companyRegistrationPlace: [
                        {required: true, message: '请选择公司註冊地', trigger: 'blur'}
                    ],
                    Zc_Street: [
                        {required: true, message: '请输入註冊地址', trigger: 'blur'},
                        {max: 255, message: '最多只能输入255字符', trigger: 'blur'}
                    ],
                    Phone: [
                        {required: true, message: '请输入聯絡電話', trigger: 'blur'},
                        {max: 50, message: '最多只能输入50字符', trigger: 'blur'}
                    ],
                    Email: [
                        {required: true, message: '请输入電子郵件', trigger: 'blur'},
                        {type: 'email', message: '请输入有效的電子郵件', trigger: 'blur'}
                    ],
                    beneficialOwners: [
                        {required: true, message: '请选择最終受益人', trigger: 'blur'}
                    ],
                    fullLegalName_1: [
                        {required: true, message: '请输入法定全名/全名', trigger: 'blur'},
                        {max: 255, message: '最多只能输入255字符', trigger: 'blur'}
                    ],
                    nationality_1: [
                        {required: true, message: '请输入公司註冊地/國籍', trigger: 'blur'}
                    ],
                    registerAddress_1: [
                        {required: true, message: '请输入註冊地址/居住地址', trigger: 'blur'},
                        {max: 2000, message: '最多只能输入2000字符', trigger: 'blur'}
                    ],
                    equity_1: [
                        {required: true, message: '请输入股權權益（%）', trigger: 'blur'},
                        {max: 255, message: '最多只能输入255字符', trigger: 'blur'}
                    ],
                    fullLegalName_2: this.formData.beneficialOwners != null && ['2', '3', '4'].includes(this.formData.beneficialOwners) ? [
                        {required: true, message: '请输入法定全名/全名', trigger: 'blur'},
                        {max: 255, message: '最多只能输入255字符', trigger: 'blur'}
                    ] : [],
                    nationality_2: this.formData.beneficialOwners != null && ['2', '3', '4'].includes(this.formData.beneficialOwners) ? [
                        {required: true, message: '请输入公司註冊地/國籍', trigger: 'blur'}
                    ] : [],
                    registerAddress_2: this.formData.beneficialOwners != null && ['2', '3', '4'].includes(this.formData.beneficialOwners) ? [
                        {required: true, message: '请输入註冊地址/居住地址', trigger: 'blur'},
                        {max: 2000, message: '最多只能输入2000字符', trigger: 'blur'}
                    ] : [],
                    equity_2: this.formData.beneficialOwners != null && ['2', '3', '4'].includes(this.formData.beneficialOwners) ? [
                        {required: true, message: '请输入股權權益（%）', trigger: 'blur'},
                        {max: 255, message: '最多只能输入255字符', trigger: 'blur'}
                    ] : [],

                    fullLegalName_3: this.formData.beneficialOwners != null && ['3', '4'].includes(this.formData.beneficialOwners) ? [
                        {required: true, message: '请输入法定全名/全名', trigger: 'blur'},
                        {max: 255, message: '最多只能输入255字符', trigger: 'blur'}
                    ] : [],
                    nationality_3: this.formData.beneficialOwners != null && ['3', '4'].includes(this.formData.beneficialOwners) ? [
                        {required: true, message: '请输入公司註冊地/國籍', trigger: 'blur'}
                    ] : [],
                    registerAddress_3: this.formData.beneficialOwners != null && ['3', '4'].includes(this.formData.beneficialOwners) ? [
                        {required: true, message: '请输入註冊地址/居住地址', trigger: 'blur'},
                        {max: 2000, message: '最多只能输入2000字符', trigger: 'blur'}
                    ] : [],
                    equity_3: this.formData.beneficialOwners != null && ['3', '4'].includes(this.formData.beneficialOwners) ? [
                        {required: true, message: '请输入股權權益（%）', trigger: 'blur'},
                        {max: 255, message: '最多只能输入255字符', trigger: 'blur'}
                    ] : [],

                    fullLegalName_4: this.formData.beneficialOwners != null && this.formData.beneficialOwners.includes('4') ? [
                        {required: true, message: '请输入法定全名/全名', trigger: 'blur'},
                        {max: 255, message: '最多只能输入255字符', trigger: 'blur'}
                    ] : [],
                    nationality_4: this.formData.beneficialOwners != null && this.formData.beneficialOwners.includes('4') ? [
                        {required: true, message: '请输入公司註冊地/國籍', trigger: 'blur'}
                    ] : [],
                    registerAddress_4: this.formData.beneficialOwners != null && this.formData.beneficialOwners.includes('4') ? [
                        {required: true, message: '请输入註冊地址/居住地址', trigger: 'blur'},
                        {max: 2000, message: '最多只能输入2000字符', trigger: 'blur'}
                    ] : [],
                    equity_4: this.formData.beneficialOwners != null && this.formData.beneficialOwners.includes('4') ? [
                        {required: true, message: '请输入股權權益（%）', trigger: 'blur'},
                        {max: 255, message: '最多只能输入255字符', trigger: 'blur'}
                    ] : [],

                    Qianziren: [
                        {required: true, message: '请输入授權簽字人', trigger: 'blur'},
                        {max: 255, message: '最多只能输入255字符', trigger: 'blur'}
                    ],
                    Yewu_Shuoming: [
                        {required: true, message: '请输入主體主要業務的說明', trigger: 'blur'},
                        {max: 2000, message: '最多只能输入2000字符', trigger: 'blur'}
                    ],
                    Zijin_Laiyuan: [
                        {required: true, message: '请输入資金來源', trigger: 'blur'},
                        {max: 2000, message: '最多只能输入2000字符', trigger: 'blur'}
                    ],
                    Shenqingren: [
                        {required: true, message: '请选择', trigger: 'blur'}
                    ],
                    IsJianguan: [
                        {required: true, message: '请选择', trigger: 'blur'}
                    ],
                    IsZhicai: [
                        {required: true, message: '请选择', trigger: 'blur'}
                    ],
                    declaration_check_1: [
                        {required: true, message: '请勾选', trigger: 'blur'}
                    ],
                    declaration_check_2: [
                        {required: true, message: '请勾选', trigger: 'blur'}
                    ],
                    file_1: [
                        {
                            required: true,
                            validator: (rule, value, callback) => {
                                if (!this.formData.file_1_List.length) {
                                    callback(new Error('请上传文件'));
                                } else {
                                    callback();
                                }
                            },
                            trigger: 'change'
                        }
                    ],
                    file_2: [
                        {
                            required: true,
                            validator: (rule, value, callback) => {
                                if (!this.formData.file_2_List.length) {
                                    callback(new Error('请上传文件'));
                                } else {
                                    callback();
                                }
                            },
                            trigger: 'change'
                        }
                    ],
                    file_3: [
                        {
                            required: true,
                            validator: (rule, value, callback) => {
                                if (!this.formData.file_3_List.length) {
                                    callback(new Error('请上传文件'));
                                } else {
                                    callback();
                                }
                            },
                            trigger: 'change'
                        }
                    ],
                    file_4: [
                        {
                            required: true,
                            validator: (rule, value, callback) => {
                                if (!this.formData.file_4_List.length) {
                                    callback(new Error('请上传文件'));
                                } else {
                                    callback();
                                }
                            },
                            trigger: 'change'
                        }
                    ],
                }
            }
        },
        methods: {
            initData() {
                ZOHO.embeddedApp.on("PageLoad", (data) => {
                    this.crmId = data.EntityId;
                    ZOHO.CRM.UI.Resize({height: "100%", width: "100%"}).then(function () {
                        app.getCRMData();
                    });
                });
            },
            getCRMData() {

                // 使用连接器，查询子表单数据
                let req_data = {
                    "parameters": {},
                    "headers": {},
                    "method": "GET",
                    "url": "https://www.zohoapis.com/crm/v7/Accounts/" + this.crmId,
                    "param_type": 2
                };
                ZOHO.CRM.CONNECTION.invoke("crm", req_data).then(async data => {
                    if (!data.code.includes("SUCCESS")) {
                        console.log("查询数据失败=" + JSON.stringify(data));
                    } else {
                        let crmData = data.details.statusMessage.data[0];
                        // console.log(JSON.stringify(crmData));
                        // app.formData = crmData;

                        // 给页面字段赋值，方便数据回传CRM
                        app.formData.Account_Name = crmData.Account_Name;
                        app.formData.companyRegistrationPlace = crmData.companyRegistrationPlace;
                        app.formData.Zc_Street = crmData.Zc_Street;
                        app.formData.Phone = crmData.Phone;
                        app.formData.Email = crmData.Email;
                        app.formData.beneficialOwners = crmData.beneficialOwners;
                        app.formData.fullLegalName_1 = crmData.fullLegalName_1;
                        app.formData.nationality_1 = crmData.nationality_1;
                        app.formData.registerAddress_1 = crmData.registerAddress_1;
                        app.formData.equity_1 = crmData.equity_1;
                        app.formData.fullLegalName_2 = crmData.fullLegalName_2;
                        app.formData.nationality_2 = crmData.nationality_2;
                        app.formData.registerAddress_2 = crmData.registerAddress_2;
                        app.formData.equity_2 = crmData.equity_2;
                        app.formData.fullLegalName_3 = crmData.fullLegalName_3;
                        app.formData.nationality_3 = crmData.nationality_3;
                        app.formData.registerAddress_3 = crmData.registerAddress_3;
                        app.formData.equity_3 = crmData.equity_3;
                        app.formData.fullLegalName_4 = crmData.fullLegalName_4;
                        app.formData.nationality_4 = crmData.nationality_4;
                        app.formData.registerAddress_4 = crmData.registerAddress_4;
                        app.formData.equity_4 = crmData.equity_4;
                        app.formData.Qianziren = crmData.Qianziren;
                        app.formData.Yewu_Shuoming = crmData.Yewu_Shuoming;
                        app.formData.Zijin_Laiyuan = crmData.Zijin_Laiyuan;

                        // 处理单选框
                        if (crmData.Shenqingren != null) {
                            app.formData.Shenqingren = crmData.Shenqingren === "是" ? 1 : 0;
                        }
                        if (crmData.IsJianguan != null) {
                            app.formData.IsJianguan = crmData.IsJianguan === "是" ? 1 : 0;
                        }
                        if (crmData.IsZhicai != null) {
                            app.formData.IsZhicai = crmData.IsZhicai === "是" ? 1 : 0;
                        }
                        // 处理 受益人数据
                        let LinkingModule6 = crmData.LinkingModule6 || [];
                        if (LinkingModule6.length > 0) {
                            const person_1 = LinkingModule6[0];
                            app.formData.fullLegalName_1 = person_1.Z_Name;
                            app.formData.nationality_1 = person_1.Z_Country;
                            app.formData.registerAddress_1 = person_1.Z_Address;
                            app.formData.equity_1 = person_1.Guquan;
                            app.formData.beneficialOwners = '1';
                        }
                        if (LinkingModule6.length > 1) {
                            const person_2 = LinkingModule6[1];
                            app.formData.fullLegalName_2 = person_2.Z_Name;
                            app.formData.nationality_2 = person_2.Z_Country;
                            app.formData.registerAddress_2 = person_2.Z_Address;
                            app.formData.equity_2 = person_2.Guquan;
                            app.formData.beneficialOwners = '2';
                        }
                        if (LinkingModule6.length > 2) {
                            const person_3 = LinkingModule6[2];
                            app.formData.fullLegalName_3 = person_3.Z_Name;
                            app.formData.nationality_3 = person_3.Z_Country;
                            app.formData.registerAddress_3 = person_3.Z_Address;
                            app.formData.equity_3 = person_3.Guquan;
                            app.formData.beneficialOwners = '3';
                        }
                        if (LinkingModule6.length > 3) {
                            const person_4 = LinkingModule6[3];
                            app.formData.fullLegalName_4 = person_4.Z_Name;
                            app.formData.nationality_4 = person_4.Z_Country;
                            app.formData.registerAddress_4 = person_4.Z_Address;
                            app.formData.equity_4 = person_4.Guquan;
                            app.formData.beneficialOwners = '4';
                        }
                        // 重置 受益人个数
                        app.changeUserForm();

                        // 处理文件数据
                        app.formData.file_1_show = true;
                        app.formData.file_2_show = true;
                        app.formData.file_3_show = true;
                        app.formData.file_4_show = true;
                        let file_1_list = []; // 存储未通过的记录
                        let file_2_list = []; // 存储未通过的记录
                        let file_3_list = []; // 存储未通过的记录
                        let file_4_list = []; // 存储未通过的记录
                        // console.log(JSON.stringify(crmData))
                        let KYC_Info = crmData.KYC_Info || [];
                        if (KYC_Info.length > 0) {
                            file_1_list = KYC_Info.filter(item => item.KYC_Name.includes("1、"));
                            file_2_list = KYC_Info.filter(item => item.KYC_Name.includes("2、"));
                            file_3_list = KYC_Info.filter(item => item.KYC_Name.includes("3、"));
                            file_4_list = KYC_Info.filter(item => item.KYC_Name.includes("4、"));
                        }
                        let passNum_file_1 = 0;
                        let passNum_file_2 = 0;
                        let passNum_file_3 = 0;
                        let passNum_file_4 = 0;
                        if (file_1_list.length > 0) {
                            file_1_list.forEach(item => {
                                if (item.Jieguo === "通过") {
                                    passNum_file_1 += 1;
                                }
                            });
                            // 所有文件都是通过，则页面就不展示
                            if (file_1_list.length === passNum_file_1) {
                                app.formData.file_1_show = false;
                            }
                        }
                        if (file_2_list.length > 0) {
                            file_2_list.forEach(item => {
                                if (item.Jieguo === "通过") {
                                    passNum_file_2 += 1;
                                }
                            });
                            // 所有文件都是通过，则页面就不展示
                            if (file_2_list.length === passNum_file_2) {
                                app.formData.file_2_show = false;
                            }
                        }
                        if (file_3_list.length > 0) {
                            file_3_list.forEach(item => {
                                if (item.Jieguo === "通过") {
                                    passNum_file_3 += 1;
                                }
                            });
                            // 所有文件都是通过，则页面就不展示
                            if (file_3_list.length === passNum_file_3) {
                                app.formData.file_3_show = false;
                            }
                        }
                        if (file_4_list.length > 0) {
                            file_4_list.forEach(item => {
                                if (item.Jieguo === "通过") {
                                    passNum_file_4 += 1;
                                }
                            });
                            // 所有文件都是通过，则页面就不展示
                            if (file_4_list.length === passNum_file_4) {
                                app.formData.file_4_show = false;
                            }
                        }

                        // crm的文件子表单数据
                        app.formData.KYC_Info = crmData.KYC_Info || [];
                    }
                }).catch((error) => {
                    console.error("获取记录时出现错误:", error);
                });
            },
            // 转换语言
            switchLanguage(language) {
            },
            // 重置表格
            resetForm(formName) {
                this.$refs[formName].resetFields();
            },
            // 最终用户个数
            changeUserForm() {
                if (this.formData.beneficialOwners.includes("1")) {
                    this.formData.finalUserShow_2 = false;
                    this.formData.finalUserShow_3 = false;
                    this.formData.finalUserShow_4 = false;
                } else if (this.formData.beneficialOwners.includes("2")) {
                    this.formData.finalUserShow_2 = true;
                    this.formData.finalUserShow_3 = false;
                    this.formData.finalUserShow_4 = false;
                } else if (this.formData.beneficialOwners.includes("3")) {
                    this.formData.finalUserShow_2 = true;
                    this.formData.finalUserShow_3 = true;
                    this.formData.finalUserShow_4 = false;
                } else if (this.formData.beneficialOwners.includes("4")) {
                    this.formData.finalUserShow_2 = true;
                    this.formData.finalUserShow_3 = true;
                    this.formData.finalUserShow_4 = true;
                }
            },

            // 上传文件到ZFS
            uploadFileToZFS(file) {
                const _file = file.raw;
                let blob = new Blob([_file], {type: "audio/wav"});
                let fileName = file.name;
                const fileContent = new File([blob], fileName, {
                    type: blob.type
                });

                var config = {
                    "CONTENT_TYPE": "multipart",
                    "PARTS": [{
                        "headers": {
                            "Content-Disposition": "file;"
                        },
                        "content": "__FILE__"
                    }],
                    "FILE": {
                        "fileParam": "content",
                        "file": fileContent
                    }
                }

                return ZOHO.CRM.API.uploadFile(config).then(function (data) {
                    // console.log(JSON.stringify(data));

                    if (data.data[0].code !== "SUCCESS") {
                        console.log("上传附件失败=" + JSON.stringify(data));
                        throw new Error("上传附件失败"); // 抛出错误，而不是返回空字符串
                    }

                    return {
                        File_Id__s: data.data[0].details.id,
                        File_Name__s: data.data[0].details.name
                    };
                }).catch(error => {
                    console.error("上传过程发生错误:", error);
                    throw error; // 继续抛出错误，让调用者处理
                });


            },

            // 提交表单
            async submitForm(formName) {
                this.isSubmitting = true; // 开始提交，设置为 true
                // 把validate方法封装成Promise
                const isValid = await new Promise((resolve) => {
                    this.$refs[formName].validate((valid) => {
                        resolve(valid);
                    });
                });

                if (!isValid) {
                    console.log('表单验证失败');
                    app.$message({
                        message: '请填写必填项',
                        type: 'error'
                    });
                    return false;
                }

                // 受益人子表单、文件子表单 置空
                let peopleEmptyUpdateData = {
                    Entity: "Accounts",
                    APIData: {
                        "id": app.crmId + "",
                        "LinkingModule6": [],
                        // "KYC_Info": [],
                    }
                }
                ZOHO.CRM.API.updateRecord(peopleEmptyUpdateData).then(function (data) {
                    // console.log(data);
                });


                // 处理单选
                app.formData.Shenqingren = app.formData.Shenqingren === 1 ? '是' : '否';
                app.formData.IsJianguan = app.formData.IsJianguan === 1 ? '是' : '否';
                app.formData.IsZhicai = app.formData.IsZhicai === 1 ? '是' : '否';

                // 处理受益人 子表单
                let peopleList = [];
                let people_1 = {
                    Z_Name: app.formData.fullLegalName_1,
                    Z_Country: app.formData.nationality_1,
                    Z_Address: app.formData.registerAddress_1,
                    Guquan: app.formData.equity_1
                };
                peopleList.push(people_1);

                if (Number(app.formData.beneficialOwners) > 1 && app.formData.fullLegalName_2 != null) {
                    let people_2 = {
                        Z_Name: app.formData.fullLegalName_2,
                        Z_Country: app.formData.nationality_2,
                        Z_Address: app.formData.registerAddress_2,
                        Guquan: app.formData.equity_2
                    };
                    peopleList.push(people_2);
                }
                if (Number(app.formData.beneficialOwners) > 2 && app.formData.fullLegalName_3 != null) {
                    let people_3 = {
                        Z_Name: app.formData.fullLegalName_3,
                        Z_Country: app.formData.nationality_3,
                        Z_Address: app.formData.registerAddress_3,
                        Guquan: app.formData.equity_3
                    };
                    peopleList.push(people_3);
                }
                if (Number(app.formData.beneficialOwners) > 3 && app.formData.fullLegalName_4 != null) {
                    let people_4 = {
                        Z_Name: app.formData.fullLegalName_4,
                        Z_Country: app.formData.nationality_4,
                        Z_Address: app.formData.registerAddress_4,
                        Guquan: app.formData.equity_4
                    };
                    peopleList.push(people_4);
                }
                app.formData.LinkingModule6 = peopleList;

                let file_1_KYC_Name = "1、注册成立文件";
                let file_2_KYC_Name = "2、受益所有人文件";
                let file_3_KYC_Name = "3、授权签字人文件";
                let file_4_KYC_Name = "4、董事文件";

                let finalFileList = [];
                // 处理文件,获取全是通过的文件
                if (this.formData.KYC_Info != null && this.formData.KYC_Info.length > 0) {
                    if (!this.formData.file_1_show) {
                        let file_1_success_list = this.formData.KYC_Info.filter(item => item.KYC_Name.includes("1、"));
                        for (const item of file_1_success_list) {
                            finalFileList.push(item);
                        }
                    }
                    if (!this.formData.file_2_show) {
                        let file_2_success_list = this.formData.KYC_Info.filter(item => item.KYC_Name.includes("2、"));
                        for (const item of file_2_success_list) {
                            finalFileList.push(item);
                        }
                    }
                    if (!this.formData.file_3_show) {
                        let file_3_success_list = this.formData.KYC_Info.filter(item => item.KYC_Name.includes("3、"));
                        for (const item of file_3_success_list) {
                            finalFileList.push(item);
                        }
                    }
                    if (!this.formData.file_4_show) {
                        let file_4_success_list = this.formData.KYC_Info.filter(item => item.KYC_Name.includes("4、"));
                        for (const item of file_4_success_list) {
                            finalFileList.push(item);
                        }
                    }

                }


                // 获取页面的文件数据
                if (this.formData.file_1_List.length > 0) {
                    for (const item of this.formData.file_1_List) {
                        let fileData = await this.uploadFileToZFS(item);
                        // console.log(JSON.stringify(fileData))
                        let kycList = [];
                        let addFile = {
                            file_id: fileData.File_Id__s,
                            file_name: fileData.File_Name__s,
                        }
                        kycList.push(addFile);
                        let tempUpdateData = {
                            KYC_Name: file_1_KYC_Name,
                            KYC: kycList,
                        };
                        finalFileList.push(tempUpdateData);
                    }
                }
                if (this.formData.file_2_List.length > 0) {
                    for (const item of this.formData.file_2_List) {
                        let fileData = await this.uploadFileToZFS(item);
                        // console.log(JSON.stringify(fileData))
                        let kycList = [];
                        let addFile = {
                            file_id: fileData.File_Id__s,
                            file_name: fileData.File_Name__s,
                        }
                        kycList.push(addFile);
                        let tempUpdateData = {
                            KYC_Name: file_2_KYC_Name,
                            KYC: kycList,
                        };
                        finalFileList.push(tempUpdateData);
                    }
                }
                if (this.formData.file_3_List.length > 0) {
                    for (const item of this.formData.file_3_List) {
                        let fileData = await this.uploadFileToZFS(item);
                        // console.log(JSON.stringify(fileData))
                        let kycList = [];
                        let addFile = {
                            file_id: fileData.File_Id__s,
                            file_name: fileData.File_Name__s,
                        }
                        kycList.push(addFile);
                        let tempUpdateData = {
                            KYC_Name: file_3_KYC_Name,
                            KYC: kycList,
                        };
                        finalFileList.push(tempUpdateData);
                    }
                }
                if (this.formData.file_4_List.length > 0) {
                    for (const item of this.formData.file_4_List) {
                        let fileData = await this.uploadFileToZFS(item);
                        // console.log(JSON.stringify(fileData))
                        let kycList = [];
                        let addFile = {
                            file_id: fileData.File_Id__s,
                            file_name: fileData.File_Name__s,
                        }
                        kycList.push(addFile);
                        let tempUpdateData = {
                            KYC_Name: file_4_KYC_Name,
                            KYC: kycList,
                        };
                        finalFileList.push(tempUpdateData);
                    }
                }
                finalFileList.forEach(item => {
                        app.formData.KYC_Info.push(item);
                    }
                )
                app.formData.KYC_Info = finalFileList;
                // app.formData.KYC_Info = finalFileList;
                // 回写数据到CRM
                app.formData.id = this.crmId + "";
                let updateData = {
                    Entity: "Accounts",
                    APIData: app.formData,
                    Trigger: ["workflow"]
                }
                // console.log(JSON.stringify(updateData));
                ZOHO.CRM.API.updateRecord(updateData).then(function (data) {
                    // console.log(JSON.stringify(data));
                    if (data.data[0].code === "SUCCESS") {
                        this.isSubmitting = false; // 提交完成，设置为 false
                        app.$message({
                            type: 'success',
                            message: '修改成功!'
                        });
                        ZOHO.CRM.UI.Popup.closeReload().then(function (data) {
                            console.log(data);
                        });
                    } else {
                        this.isSubmitting = false; // 验证失败，设置为 false
                        app.$message({
                            message: data.data[0].message,
                            type: 'error'
                        });
                    }
                });


            },
            // 处理超出文件数量限制
            handleExceed(files, fileList) {
                this.$message.warning(`最多只能上传 5 个文件`);
            },
            // 上传前校验（文件选择时触发）
            beforeAvatarUpload(file) {
                return this.validateFile(file);
            },
            // 获取文件扩展名
            getFileExtension(fileName) {
                return fileName.split('.').pop().toLowerCase();
            },
            // 校验单个文件
            validateFile(file) {
                // 1. 校验文件类型
                const ext = this.getFileExtension(file.name);
                const isValidType = this.allowedExtensions.includes(ext);
                if (!isValidType) {
                    this.$message.error(`文件 "${file.name}" 格式不支持！`);
                    return false;
                }

                // 2. 校验文件大小
                const isAllowedSize = file.size <= this.MAX_FILE_SIZE;
                if (!isAllowedSize) {
                    this.$message.error(`文件 "${file.name}" 大小 (${(file.size / 1024 / 1024).toFixed(2)}MB) 超过 20MB 限制！`);
                    return false;
                }

                return true;
            },
            // 文件列表变化时更新表单状态
            handleChange(file, fileList, type) {

                if (file === undefined || fileList === undefined) {
                    return false;
                }
                // 校验文件
                const isValid = this.validateFile(file);

                // 如果文件有效，更新 fileList；否则过滤掉无效文件
                if (isValid) {
                    // 更新文件列表
                    if (type === 1) {
                        this.formData.file_1_List = [...fileList];
                    } else if (type === 2) {
                        this.formData.file_2_List = [...fileList];
                    } else if (type === 3) {
                        this.formData.file_3_List = [...fileList];
                    } else if (type === 4) {
                        this.formData.file_4_List = [...fileList];
                    }
                } else {
                    // 移除无效文件
                    if (type === 1) {
                        this.formData.file_1_List = fileList.filter(f => f.uid !== file.uid);
                    } else if (type === 2) {
                        this.formData.file_2_List = fileList.filter(f => f.uid !== file.uid);
                    } else if (type === 3) {
                        this.formData.file_3_List = fileList.filter(f => f.uid !== file.uid);
                    } else if (type === 4) {
                        this.formData.file_4_List = fileList.filter(f => f.uid !== file.uid);
                    }
                }
                // console.log(this.formData.file_1_List)
                return this.validateFile(file);
            },

            // 处理文件移除
            handleRemove(file, fileList) {
                this.formData.file_1_List = [...fileList];
            },
        }
    });
</script>
</body>
</html>
